package cn.shyouchi.wuguanjia.android.ui;

import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.impl.SubscriberOnNextListener;
import cn.shyouchi.wuguanjia.android.ui.home.property.PropertyMainActivity;
import cn.shyouchi.wuguanjia.android.widget.dialog.CongratulationDialogFragment;

public class ImprovePropertyInfoActivity extends AppCompatActivity implements
        CongratulationDialogFragment.CongratulationDialogListener {

    @BindView(R.id.property_register_name_edit_text) EditText nameEditText;
    @BindView(R.id.property_register_company_edit_text) EditText companyEditText;
    @BindView(R.id.property_register_position_edit_text) EditText positionEditText;
    @BindView(R.id.property_register_email_edit_text) EditText emailEditText;

    private static final String TAG = "ImprovePropertyInfo";

    private SubscriberOnNextListener propertyRegisterOnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_improve_property_info);

        ButterKnife.bind(this);

        propertyRegisterOnNext = new SubscriberOnNextListener<String>() {
            @Override
            public void onNext(String data) {
                Log.d(TAG, data);
                DialogFragment dialog = new CongratulationDialogFragment();
                dialog.show(getFragmentManager(), "CongratulationDialogFragment");
            }
        };
    }

    @OnClick(R.id.property_register_submit_button)
    void propertyRegisterSubmitButtonTapped() {

        if (nameEditText.getText().toString().isEmpty()) {
            Toast.makeText(this, "请输入您的姓名", Toast.LENGTH_SHORT).show();
            return;
        }
        if (companyEditText.getText().toString().isEmpty()) {
            Toast.makeText(this, "请输入您的公司名称" , Toast.LENGTH_SHORT).show();
            return;
        }
        if (positionEditText.getText().toString().isEmpty()) {
            Toast.makeText(this, "请输入您的职位", Toast.LENGTH_SHORT).show();
            return;
        }
        if (emailEditText.getText().toString().isEmpty()) {
            Toast.makeText(this, "请输入您的邮箱", Toast.LENGTH_SHORT).show();
            return;
        }

//        Realm realm = Realm.getDefaultInstance();
//        final User user = realm.where(User.class).findAll().first();

//        HttpMethods.getInstance().propertyRegister(new ProgressSubscriber(propertyRegisterOnNext, ImprovePropertyInfoActivity.this),
//                user.getUsername(), user.getPassword(),
//                nameEditText.getText().toString(), companyEditText.getText().toString(),
//                positionEditText.getText().toString(), emailEditText.getText().toString()
//        );
    }

    @Override
    public void onCongratulationDialogPositiveClick(DialogFragment dialog) {
        startActivity(new Intent(this, PropertyMainActivity.class));
    }

    @Override
    public void onCongratulationDialogTimeUp(DialogFragment dialog) {
        startActivity(new Intent(this, PropertyMainActivity.class));
    }
}
